
<html>
<head>

<title>Specialization Analytics</title>
</head>
<body>


<%-- Import the java.sql package --%>
            <%@ page import="java.sql.*"%>
            <%-- -------- Open Connection Code -------- --%>
            <%
            
            Connection conn = null;
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            Statement stmt =null;
            
            
    try{   
                // Registering Postgresql JDBC driver with the DriverManager
                Class.forName("org.postgresql.Driver");

                // Open a connection to the database using DriverManager
                conn = DriverManager.getConnection(
                		"jdbc:postgresql://localhost:5433/GradApp?" +
                        "user=postgres&password=20880130");
                
      %>
      <table>
      <%
      stmt = conn.createStatement();
      String QuaryString = "SELECT Specialization.name, count(*),Specialization.id "+
                          "FROM Students,Specialization " +
                          "WHERE Students.specialization=Specialization.id  "+
                          "GROUP BY Specialization.name,Specialization.id";
      rs = stmt.executeQuery(QuaryString);
      
    	  %>
    	  <tr>
    	  <th> Specialization</th>
    	  <th> Number of Applications</th>
    	  </tr>
    	 <% while (rs.next()){ %>
    	  <tr>
    	  <td> <%=rs.getString(1) %></td>
    	  <td> <a href="Applications.jsp?SpecApp=<%=rs.getInt(3)%>"><%=rs.getInt(2)%></a></td> 
    	    
    	  </tr>
      <%   
      }
      %>	    
            
   
      </table>
      
      
      <%
                
            } catch (SQLException e) {

                // Wrap the SQL exception in a runtime exception to propagate
                // it upwards
                throw new RuntimeException(e);
            }
            finally {
                // Release resources in a finally block in reverse-order of
                // their creation

                if (rs != null) {
                    try {
                        rs.close();
                    } catch (SQLException e) { } // Ignore
                    rs = null;
                }
                if (pstmt != null) {
                    try {
                        pstmt.close();
                    } catch (SQLException e) { } // Ignore
                    pstmt = null;
                }
                if (conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) { } // Ignore
                    conn = null;
                }
            } 
    %>
      
                
     
                
                
                


</body>
</html>